﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UL360DataNET40;

namespace UL360Admin.Survey.Utils
{
    public static class Logger
    {
       public static string LogNewEntry(string methodName, string message, int loggingLevel)
        {
            //Make new entry in db
            using (var db = new UL360Entities())
            {
                //Time for entry
                DateTime time = DateTime.Now;

                //Add entry and save
                db.SurveyLoggings.Add(new SurveyLogging { Time = time, LogLevel = loggingLevel, MethodName = methodName, Exception = message });
                db.SaveChanges();

                //Get id
                int id = db.SurveyLoggings.OrderByDescending(l => l.SurveyLoggingId).FirstOrDefault().SurveyLoggingId;

                //String to return with id of entry
                return id.ToString();
            }
        }
    }
}
